//index.js
//获取应用实例
const app = getApp();
Page({
  onReady: function (e) {
    this.mapCtx = wx.createMapContext('myMap');
  },
  data: {
    markers: [
      {
        iconPath: "../../images/mark.png",
        id: 0,
        latitude: 23.099994,
        longitude: 113.324520,
        width: 30,
        height: 30
      }
    ],
    controls: [
      {
        id: 1,
        iconPath: '../../images/location.png',
        position: {
          top: 10,
          left: 10,
          width: 30,
          height: 30
        },
        clickable: true
      }
    ]
  },
  bindmarkertap: function (e) {
    const markerId = e.markerId;
    console.log(markerId);
  },
  controltap: function (e) {
    const controlId = e.controlId;
    if (controlId === 1) {
      wx.getLocation({
        type: 'wgs84',
        success: (res) => {
          const latitude = res.latitude;
          const longitude = res.longitude;
          const speed = res.speed;
          const accuracy = res.accuracy;
          this.setData({
            markers: [
              {
                iconPath: "../../images/mark.png",
                id: 0,
                latitude: latitude,
                longitude: longitude,
                width: 30,
                height: 30
              }
            ]
          });
          this.mapCtx.moveToLocation();
          console.log(latitude, longitude, speed, accuracy);
        }
      })
    }
  },
  onLoad: function () {
    const that = this;
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
  },
  onShareAppMessage: function () {
    return {
      title: '千里眼'
    }
  }
});
